package subString;

/*
 *@description 验证回文串
 *@author hkfan
 *@version 1.0
 *@create 2025/5/19 17:26
 */
public class LeetCode_125 {
    public boolean isPalindrome(String s) {
        s = update(s);
        System.out.println(s);
        StringBuilder str1 = new StringBuilder(s);
        StringBuilder str2 = new StringBuilder(str1.reverse().toString());
        return str2.toString().equals(str1.toString());
    }

    private String update(String s) {

        StringBuilder str = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if ((s.charAt(i)>='a' && s.charAt(i)<='z')||s.charAt(i)>='A' && s.charAt(i)<='Z'){
                str.append(Character.toLowerCase(s.charAt(i)));
            }
            if (s.charAt(i)>='0' && s.charAt(i)<='9'){
                str.append(Character.toLowerCase(s.charAt(i)));
            }
        }
        return str.toString();

    }
}
